/*
 * FilledRect.cpp
 *
 *  Created on: Jul 6, 2009
 *      Author: kurt
 */

#include "FilledRect.h"
#include "DrawingCanvas.h"
#include "GraphicsInstance.h"
#include <GL/gl.h>
#include <sstream>
using namespace std;
using namespace objdraw;

FilledRect::~FilledRect() 
{
	
}
FilledRect::FilledRect() 
{
	start = Location(0,0);
	end = Location(0,0);
	color = Color(0,0,0);
	hidden = false;
	canvas = NULL;
}
FilledRect::FilledRect(const FilledRect & r)
{
	start = r.start;
	end = r.end;
	color = r.color;
	hidden = r.hidden;
	canvas = r.canvas;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FilledRect::FilledRect(float x, float y, float width, float height, DrawingCanvas * c)
{
	start = Location(x,y);
	end = Location(x+width, y+height);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FilledRect::FilledRect(Location origin, float width, float height, DrawingCanvas * c)
{
	start = origin;
	end = Location(origin.x+width, origin.y+height);
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
FilledRect::FilledRect(Location p0, Location p1, DrawingCanvas * c)
{
	start = p0;
	end = p1;
	color = Color(0,0,0);
	hidden = false;
	canvas = c;
	if(canvas != NULL)
		canvas->getCanvasContent().addDrawable(this);
}
void FilledRect::render()
{
	if(hidden) return;
	
	glEnable2D();
	glDisable(GL_TEXTURE_2D);
	
	glBegin(GL_QUADS);
		color.use();
		glVertex2f(start.x,start.y);
		glVertex2f(end.x,start.y);
		glVertex2f(end.x,end.y);
		glVertex2f(start.x,end.y);
	glEnd();

	glDisable(GL_TEXTURE_2D);
	glDisable2D();
}
string FilledRect::toString()
{
	stringstream rstr("FilledRect: ");
	rstr << "start: " << start.toString() << 
	"end: " << end.toString() << 
	"color: " << color.toString() <<
	"hidden: " << hidden;
	return rstr.str();
}
